package com.irdstudio.efp.nls.api.rest;

import java.util.List;
import java.util.Map;

import com.irdstudio.basic.framework.core.constant.DataRuleType;
import com.irdstudio.basic.framework.core.constant.PubConstant;
import com.irdstudio.efp.e4a.service.facade.SRoleDataRuleService;
import com.irdstudio.efp.loan.service.vo.AccLoanVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.irdstudio.basic.framework.core.constant.ResponseData;
import com.irdstudio.basic.framework.web.controller.AbstractController;
import com.irdstudio.efp.limit.service.facade.LmtAdjustThirdService;
import com.irdstudio.efp.limit.service.vo.LmtAdjustThirdVO;

/**
 * 
 * TODO 额度调整
 * 
 * @author wanglihua
 * @since 2019年3月14日 下午7:18:59
 * @version 1.0
 */

@RestController
@RequestMapping("/api")
public class LmtAdjustThirdController extends AbstractController {

	@Autowired
	@Qualifier("lmtAdjustThirdService")
	private LmtAdjustThirdService lmtAdjustThirdService;

	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;


	@PostMapping(value = "/lmt/adjust/third/apps")
	public @ResponseBody ResponseData<List<LmtAdjustThirdVO>> queryAllOwner(@RequestBody LmtAdjustThirdVO vo) {
		List<LmtAdjustThirdVO> outputVo = null;
		Map<String,String> dataRuleTypeMap = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		vo.setPrdCodebyBaseInfo(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PRD_CODE));
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataRuleTypeMap == null ? null:dataRuleTypeMap.get(PubConstant.PERMIS_TYPE));
		setUserInfoToVO(vo);
		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
			case Owner:
				outputVo = lmtAdjustThirdService.queryAllOwner(vo);
				break;
			case CurrOrg:
				outputVo = lmtAdjustThirdService.queryAllCurrOrg(vo);
				break;
			case CurrDownOrg:
				outputVo = lmtAdjustThirdService.queryAllCurrDownOrg(vo);
				break;
			case CurrOwnerPrd:
				outputVo = lmtAdjustThirdService.queryAllCurrOwnerPrd(vo);
				break;
			default:
				outputVo = lmtAdjustThirdService.queryAllOwner(vo);
				break;
		}
		return getResponseData(outputVo);
	}
}
